(function(){
	var _Tool = function(){
	};
	
	// 删除操作
	_Tool.prototype.del = function(url,params){
		Dialog.confirm('警告：确定要删除这条记录？',function(){
			$.ajax({
				url : url,
				type : 'post',
				data : params,
				dataType: 'text',
				cache: false,
				success:function(data){
					Dialog.alert(data,function(){
						Page.queryPage();
					});
				},
				error:function(data){
					Dialog.alert("操作失败！");
				}
			});
		});
	};
	
	// 打开保存表单的窗口
	_Tool.prototype.showSaveDialog = function(fromUrl,toUrl,title,width,height){
		var diag = new Dialog();
		diag.URL = fromUrl;
		diag.Title = title;
		setDialog(diag,width,height);
		diag.OKEvent = function(){//点击确定后调用的方法
			 $("#modelForm",diag.innerFrame.contentWindow.document).ajaxSubmit({
				 url: toUrl,
				 type : 'post',
				 dataType: 'text',
				 success: function (data) {
					 Dialog.alert(data,function(){
						 diag.close();
						 Page.queryPage();
					 });
	             },
	             error : function(data){
	            	 Dialog.alert("操作失败！");
	             }
			 });
			 return false;
		};
		diag.show();
		return diag;
	};
	
	// 打开修改表单的窗口
	_Tool.prototype.showUpdateDialog = function(fromUrl,toUrl,title,width,height){
		var diag = new Dialog();
		diag.URL = fromUrl;
		diag.Title = title;
		setDialog(diag,width,height);
		diag.OKEvent = function(){//点击确定后调用的方法
			 $("#modelForm",diag.innerFrame.contentWindow.document).ajaxSubmit({
				 url: toUrl,
				 type : 'post',
				 dataType: 'text',
				 success: function (data) {
					 Dialog.alert(data,function(){
						 diag.close();
						 Page.queryPage();
					 });
	             },
	             error : function(data){
	            	 Dialog.alert("操作失败！");
	             }
			 });
			 return false;
		};
		diag.show();
		return diag;
	};
	
	// 弹出一个窗口
	_Tool.prototype.showDialog = function(url,title,width,height){
		var diag = new Dialog();
		diag.URL = url;
		diag.Title = title;
		setDialog(diag,width,height);
		diag.show();
		return diag;
	}
	
	// 弹出一个可回调窗口
	_Tool.prototype.showCallbackDialog = function(fromUrl,toUrl,title,width,height,callback){
		var diag = new Dialog();
		diag.URL = fromUrl;
		diag.Title = title;
		setDialog(diag,width,height);
		diag.OKEvent = function(){//点击确定后调用的方法
			 $("#modelForm",diag.innerFrame.contentWindow.document).ajaxSubmit({
				 url: toUrl,
				 type : 'post',
				 dataType: 'text',
				 success: function (data) {
					 diag.close();
					 if(null != callback && undefined != callback){
						 callback.call(this,data);
					 }
	             },
	             error : function(data){
	            	 Dialog.alert("操作失败！");
	             }
			 });
			 return false;
		};
		diag.show();
		return diag;
	}
	
	// 设置弹出窗口的属性
	function setDialog(diag,width,height){
		if(isNotEmpty(width)){
			diag.Width = width;
		}
		if(isNotEmpty(height)){
			diag.Height = height;
		}
	}
	
	window.Tool = new _Tool();
})();